package bch.kafka.integrate.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaAdmin;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class KafkaTopicConfig {

    // 1. KafkaAdmin Bean，用于自动创建 Topic
    @Bean
    public KafkaAdmin kafkaAdmin() {
        Map<String, Object> configs = new HashMap<>();
        configs.put("bootstrap.servers", "localhost:9092"); // Kafka 地址
        return new KafkaAdmin(configs);
    }

    // 2. 定义要创建的 Topic
    @Bean
    public NewTopic userEventsTopic() {
        return new NewTopic("user-events", 1, (short) 1); // topic名、分区数、副本数
    }
}
